EF code first error "The specified index already exists. [ IX_Id ]" for object tree
Posted
by
PascalN
on Stack Overflow
See other posts from Stack Overflow
or by PascalN
Published on 2012-03-30T23:18:33Z
Indexed on
2012/09/29
3:37 UTC
Read the original article
Hit count: 170
entity-framework
Using EF code first 4.3 I'm trying to model an object tree with a required-required relationships and a required-optional relationships.
Here is a simple representation of those classes
public class Top
{
public int Id { get; set; }
public virtual Middle Middle { get; set; }
}
public class Middle
{
public int Id { get; set; }
public virtual Child Child { get; set; }
}
public class Child
{
public int Id { get; set; }
}
Here is the OnModelCreating code
modelBuilder.Entity<Top>().HasRequired(t => t.Middle).WithRequiredPrincipal().WillCascadeOnDelete();
modelBuilder.Entity<Middle>().HasRequired(t => t.Child).WithOptional().WillCascadeOnDelete();
This produces the error "The specified index already exists. [ IX_Id ]" on SQLCE
After checking the db schema, both model binder fluent API configuration lines create an index IX_Id on the table Middles.
Does anyone know how to work around that problem?
Is there a way to set the index name?
Thank you! Pascal
© Stack Overflow or respective owner